package cn.com.taurus.controller.getdata;
import cn.com.taurus.biz.*;
import cn.com.taurus.entity.*;
import cn.com.taurus.impl.*;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.servlet.ModelAndView;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Random;

/**
 * @author zhy
 * @createTime 2021-6-9 14:37:46
 * @remark 获取数据控制层
 * @version 1.0
 */

/**
 * Ambiguous mapping. Cannot map 'xxxController' method 问题
 * 如果RequestMapping里面的路径重复了，就会报这个错
 */
@RestController
public class GetDataJsonController {
    @Autowired
    FundValueChangeImpl fundValueChangeImpl;
    @Autowired
    ClientBiz clientBiz;
    @Autowired
    DealRecordBiz dealRecordBiz;
    @Autowired
    CountClientBiz countClientBiz;


    @Autowired
    private RedeemRecordBiz redeemRecordBiz;
    @Autowired
    SystemNoticeBiz systemNoticeBiz;
    @Autowired
    private FundAndFundTypeBiz fundAndFundTypeBiz;

    //基金净值变化数据
    List<FundValueChange> fundValueChangeData = new ArrayList<>();

    //计算获取基金净值变化数据的次数
    int getFundValueChangeDataCount;


    @ResponseBody
    @RequestMapping(value = "/Anonymous/content",produces = {"text/plain;charset=UTF-8"})
    public String announcement(){
        Random random = new Random();
        String str = systemNoticeBiz.selectSystemNotice(random.nextInt(28)+1);
        str="{\"str\":\""+str+"\"}";
        System.out.println(str+"666666");
        return str;
    }


    @RequestMapping("/Anonymous/selectFundValueChangeData.do")
    public String getFundValueChangeData(String fId){
        Gson gson = new Gson();
        List list = fundValueChangeImpl.selectFundValueChange(fId);
        String str = gson.toJson(list);

//        str="{\"code\":0,\"msg\":\"\",\"count\":0,\"data\":"+ str+"}";
//        System.out.println(str);
        return str;
    }

    @RequestMapping("/Anonymous/selectClientOne.do")
    public String selectClientOne(Model model) {
        Gson gson = new Gson();
        List list = clientBiz.selectOne();
        String str = gson.toJson(list);
        return str;
    }


    @RequestMapping("/Anonymous/selectRedeemRecord.do")
    public String selectRedeemRecord(String redeemTime,String time) {
        Gson gson = new Gson();
        Integer num1 = redeemRecordBiz.selectOne(redeemTime,time);
        Integer num2 = dealRecordBiz.selectOne(redeemTime,time);
        if (num1 == null){
            num1=0;
        }
        if (num2 == null){
            num2=0;
        }
        Integer num = num1+num2;
        String str = gson.toJson(num);
        return str;
    }

    @RequestMapping("/Anonymous/selectFundType.do")
    public String selectFundType(Model model,String ftName) {
        Gson gson = new Gson();
        int num = fundAndFundTypeBiz.selectFundType(ftName);
        String str = gson.toJson(num);
        return str;
    }


    @RequestMapping("/Anonymous/selectCountClientOne.do")
    public String selectCountClientOne(String countTime,String time) {
        Gson gson = new Gson();
        int num = countClientBiz.selectOne(countTime,time);
        String str = gson.toJson(num);
        return str;
    }
}
